package com.cqq.print.business.service.impl;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cqq.print.business.dao.POrderDetailDao;
import com.cqq.print.business.dao.domain.POrderDetail;
import com.cqq.print.business.service.bean.POrderDetailBean;


/**
 * @author generated
 * @date 2015-07-01
 */


@Service(value="pOrderDetailService")
public class POrderDetailServiceImpl implements com.cqq.print.business.service.POrderDetailService{

             @Autowired
             private POrderDetailDao pOrderDetailDao;

			
			public void insertSelective(List<POrderDetailBean> listDetailBean) throws Exception {
				if(listDetailBean ==null||listDetailBean.size()<=0)
					throw new Exception("listDetailBean is null");
				for (POrderDetailBean detailBean : listDetailBean) {					
					POrderDetail detail = new POrderDetail();
					BeanUtils.copyProperties(detailBean, detail);
					pOrderDetailDao.insertSelective(detail);
				}
				
			}

			
			public void insertSelective(POrderDetailBean detailBean)
					throws Exception {
				if(detailBean ==null)
					throw new Exception("detailBean is null");
				if(detailBean.getOrderId()==null||detailBean.getOrderId()<0)
					throw new Exception("orderId is null");
				POrderDetail detail = new POrderDetail();
				BeanUtils.copyProperties(detailBean, detail);
				pOrderDetailDao.insertSelective(detail);
			}

			
			public List<POrderDetailBean> queryDetailsByOrderId(int orderId) {
				List<POrderDetail> listDetail = pOrderDetailDao.queryDetailsByOrderId(orderId);
				List<POrderDetailBean> listDetailBean = null;
				if(listDetail!=null&&listDetail.size()>0){
					listDetailBean = new ArrayList<POrderDetailBean>();					
					for (POrderDetail detail : listDetail) {					
						POrderDetailBean detailBean = new POrderDetailBean();
						BeanUtils.copyProperties(detail, detailBean);
						listDetailBean.add(detailBean);
					}
				}
				return listDetailBean;
			}

			
			public void deleteDetailById(int id) {
				pOrderDetailDao.deleteByPrimaryKey(id);
			}

			
			public void deleteDetailsByOrderId(int orderId) {
				pOrderDetailDao.deleteByOrderId(orderId);
			}

}